package cn.itcast.bos.service.impl;

import cn.itcast.bos.domain.system.Menu;
import cn.itcast.bos.repository.MenuRepository;
import cn.itcast.bos.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class MenuServiceImpl implements MenuService {

	@Autowired
	private MenuRepository menuRepository;

	@Override
	public List<Menu> findAll() {
		return menuRepository.findAll();
	}

	@Override
	public void save(Menu menu) {
		// 放置用户没有选中父菜单，需要设置为null，不能保存0的值，表示保存父菜单
		if(menu.getParentMenu() != null && menu.getParentMenu().getId() == 0){
			menu.setParentMenu(null);
		}
		// 调用DAO，保存
		menuRepository.save(menu);
	}
}
